package org.example;

import org.example.bootstrap.ConsumerBootstrap;
import org.example.common.model.User;
import org.example.common.service.UserService;
import org.example.consumer.UserServiceProxy;
import org.example.proxy.ServiceProxyFactory;

/**
 * Hello world!
 *
 */
public class Consumer
{
    public static void main( String[] args ) {
        // 得到支持远程调用服务提供者的代理对象
        // 静态代理
//        UserService userService = new UserServiceProxy();
        // 动态代理
//        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
//
//        User user = new User();
//        user.setName("张三");
//        User newUser = userService.getUser(user);
//        if(newUser != null){
//            System.out.println("用户名：" + newUser.getName());
//        } else {
//            System.out.println("用户不存在");
//        }
//
//        long nubmer = userService.getNumber();
//        System.out.println("number：" + nubmer);

        // 初始化
        ConsumerBootstrap.init();

        // 获取代理
        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("张三");
        // 调用
        User newUser = userService.getUser(user);
        if(newUser != null){
            System.out.println("用户名：" + newUser.getName());
        } else {
            System.out.println("用户不存在");
        }
    }
}
